package thread.reentranLock;

import java.util.concurrent.locks.ReentrantLock;

public class BaseTest {
    public static void main(String[] args) {
        Myservice myservice=new Myservice();

       new MyThread(myservice).start();
       new MyThread(myservice).start();
       new MyThread(myservice).start();
       new MyThread(myservice).start();
       new MyThread(myservice).start();
    }


}
class MyThread extends Thread{
    private Myservice myservice;

    public MyThread(Myservice myservice) {
        this.myservice = myservice;
    }

    @Override
    public void run() {
        myservice.testMethod();
    }
}

class Myservice {

    private ReentrantLock lock=new ReentrantLock();

    public void testMethod(){
        lock.lock();
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+" "+i);
        }
        lock.unlock();
    }




}
